import { editor } from "@codingame/monaco-editor";
import { FileManager } from "../FileManager";
import { monaco } from "@codingame/monaco-editor-wrapper";
export const Save = () => {
    return {
        name: "save",
        setup(this: FileManager, ed: editor.IStandaloneCodeEditor) {
            const save = () => {
                const fileModel = this.findFileCache(ed.getModel()!);
                if (fileModel) this.saveFile(fileModel.path);
            };
            ed.onDidChangeModelContent(() => {
                const fileModel = this.findFileCache(ed.getModel()!);
                if (fileModel) this.hub.emit("unSave", fileModel.path);
            });

            ed.addAction({
                id: "save",
                label: "save",
                keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
                contextMenuGroupId: "file_explorer",
                run: save, // 点击后执行的操作
            });
        },
    };
};
